package Netzwerkprogrammierung.g4.Sockets;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class TCPClient {
	
	public static void main(String[] args) throws UnknownHostException, IOException {

		Scanner s = new Scanner(System.in);
		System.out.print("Bitte eine Nachricht eingeben: ");
		String sentence = s.nextLine();
		sentence += System.getProperty("line.separator");
		
		Socket clientSocket = new Socket("localhost", 6789);
		
		DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());

		BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
		
		outToServer.writeBytes(sentence);

		String modifiedSentence = inFromServer.readLine();
		System.out.println("FROM SERVER: "+ modifiedSentence);
		
		outToServer.close();
		inFromServer.close();
		
		clientSocket.close();
	}
}
